//
//  CertExtendedKeyUsage.m
//  TestProject
//
//  Created by 毕武侠 on 2022/2/19.
//  Copyright © 2022 zhulong. All rights reserved.
//

#import "CertExtendedKeyUsage.h"
#import "CertTLV.h"
#import "CertOID.h"

@implementation CertExtendedKeyUsage

- (void)loadCertData {
    self.extendedKeyUsage = [self getList:self.data type:0x30];
}

- (id)getObject:(NSData *)data type:(uint16_t)type {
    char *sdata = (char *)data.bytes;
    if (type == 0x130 && (uint8_t)sdata[0] == 0x06) {
        return [CertTLV value:sdata begin:0];
    }
    return nil;
}

- (NSString *)description {
    NSMutableString *str = [NSMutableString string];
    for (int i = 0; i < self.extendedKeyUsage.count; i++) {
        [str appendFormat:@"%@(%@), ", self.extendedKeyUsage[i], [CertOID oid:self.extendedKeyUsage[i]]];
    }
    if (str.length > 0) {
        [str insertString:@"[" atIndex:0];
        [str deleteCharactersInRange:NSMakeRange(str.length-2, 2)];
        [str appendString:@"]"];
    }
    return str;
}

@end
